import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/http_data.dart';
import 'package:app/src/http/bean/wroks/oem_auditing_product_bean.dart';
import 'package:app/src/http/bean/wroks/special_clauses.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';
import 'package:app/src/utils/image_path_utils.dart';

import '../../../../app_ui.dart';

///更换工厂
class UiOrderschangeFactory {
  ///factories 工厂集合
  ///changeFactoryId 当前更换工厂的ID;即：当前选中的工厂
  static Widget build(
      BuildContext context, List<Factory>? factories, String? changeFactoryId,
      {String? title}) {
    var data = factories;
    if (StringUtils.isEmpty(data)) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    if (StringUtils.isEmpty(title)) {
      title = AppStrings.of(context).OrderschangeFactory;
    }
    children.add(
        UiBase.title(context, title, bottom: AppEdgeInsets.margin_bottom)); //标题
    if (data != null && changeFactoryId != null) {
      children.add(_wrap(context, data, changeFactoryId));
    }
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }

  static Widget _wrap(
      BuildContext context, List<Factory> factories, String changeFactoryId) {
    List<Widget> children = [];
    factories.forEach((element) {
      children.add(_text(element.FactoryName,
          isBlue: changeFactoryId == element.FactoryId));
    });
    return Wrap(
      children: children,
      direction: Axis.horizontal,
      spacing: 4,
      alignment: WrapAlignment.start,
    );
  }

  static Widget _text(String? text, {bool isBlue = false}) {
    TextStyle? style = null;
    if (isBlue) {
      style = AppStyle.textStyleWithCardBlue();
    } else {
      style = AppStyle.textStyleWithCard();
    }
    return Text(
      text ?? "",
      style: style,
    );
  }
}
